package nature.nano.util.pipe;

import nature.nano.component.EmptyProps;
import nature.nano.component.PrimaryPipe;
import nature.nano.component.Strings;
import nature.nano.iface.Props;

public class ErrorCatcher extends PrimaryPipe {
	
	@Override
	public void anBegin(String type, Props props) {
		slot(Strings.error).onBegin(type, props);
		if (props == null) {
			props = EmptyProps.instance;
			error(
				Strings.error,
				Strings.method, Strings.onBegin,
				Strings.type, Strings.propsIsNull);
		}
		try {
			slot(Strings.output).onBegin(type, props);
		} catch (Exception e) {
			error(
				Strings.error,
				Strings.method, Strings.onBegin,
				Strings.type, e.toString());
		}
	}

	@Override
	public void anContent(String content) {
		slot(Strings.error).onContent(content);
		try {
			slot(Strings.output).onContent(content);
		} catch (Exception e) {
			error(
				Strings.error,
				Strings.method, Strings.onContent,
				Strings.type, e.toString());		
		}
	}

	@Override
	public void anEnd(String type) {
		try {
			slot(Strings.output).onEnd(type);
		} catch (Exception e) {
			error(
				Strings.error,
				Strings.method, Strings.onEnd,
				Strings.type, e.toString());		
		}
		slot(Strings.error).onEnd(type);
	}
	
}
